from flask import Blueprint,request,jsonify
import json
from database import db
bp_user = Blueprint('user',__name__)

@bp_user.route('/login')
def login():
    #获取用户名和密码
    data = json.loads(request.data)
    mobile = data['mobile']
    password = data['password']
    #通过用户名查询
    sql = "select * from cuser where mobile=%s"%(mobile)
    user = db.findone(sql)
    #如果存在判断密码是否正确
    if user:
        if user['password'] == password:
            return jsonify({'code':200,'userid':user['id']})
        else:
             return jsonify({'code':10011})
    else:
    #不存在直接返回10010
        return jsonify({'code':10010})



